﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class User_Address_DefaultController : UserController
    {
        public IUser_addr_bookService _user_addr_book { get; set; }
        [Authorize]
        [HttpGet]
        public IActionResult Get(int id)
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                return Ok(new { status = 0, msg = "用户尚未登录或已超时!" });
            }
            if (_user_addr_book.Exists(id, userModel.user_name))
            {
                _user_addr_book.SetDefault(id, userModel.user_name);
                return Ok(new { status = 1, msg = "默认收货地址设置成功！" });
            }
            return Ok(new { status = 0, msg = "该记录不存在或已删除！" });
        }
    }
}